<template>
  <div class="home">
    <!-- 头部导航 -->
    <van-nav-bar title="免费直播课" left-arrow @click-left="$router.go(-1)" />
    <!-- 内容区 -->
    <div class="all" v-if="zhoboList.length > 0">
      <div class="list" v-for="(item, index) in zhoboList" :key="index">
        <div class="t1">{{ item.course_classify_title }}</div>
        <div class="t2">{{ item.title }}</div>
        <div class="t3">
          <van-tag
            round
            type="default"
            size="medium"
            v-for="(ite, ind) in item.course_label"
            :key="ind"
            style="margin-right: 10px"
            >{{ ite.label_name }}</van-tag
          >
        </div>
        <div class="t4">
          <div
            class="tu"
            v-for="(ite, ind) in item.teacher.slice(0, 3)"
            :key="ind"
          >
            <img :src="ite.avatar" alt="" class="img" />
            <div class="zi" style="margin-top: 10px; font-size: 12px">
              {{ ite.teacher_name }}
            </div>
          </div>
        </div>
        <div class="t5">
          <div style="margin-bottom: 10px">
            {{ item.stock_num == 0 ? '' : `限${item.stock_num}人` }}
          </div>
          <div class="dis">
            <div class="l">{{ item.sales_num }}人已报名</div>
            <div class="r" style="color: green" v-if="item.price == 0">
              免费
            </div>
            <div class="r" style="color: red" v-else>￥{{ item.price }}</div>
          </div>
        </div>
      </div>
    </div>
    <!-- 空状态 -->
    <van-empty description="暂无该数据哦!" v-else />
  </div>
</template>

<script>
import { toRefs, reactive, onMounted } from 'vue'
import { useRoute } from 'vue-router'
import { Toast } from 'vant'
import { getShouYeListApi } from '../http/api.js'
export default {
  setup(props) {
    const route = useRoute()
    const data = reactive({
      zhoboList: []
    })
    onMounted(() => {
      console.log('xq传的数据', route.query.id)
      getZHIbOList()
    })
    // 直播详情数据
    const getZHIbOList = async () => {
      const resall = await getShouYeListApi(route.query.id)
      console.log('所有的数据页面详情', resall)
      data.zhoboList = resall.course_list
    }
    return {
      ...toRefs(data)
    }
  }
}
</script>
<style lang="scss" scoped>
.home {
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  padding: 5px 20px;
  padding-bottom: 90px;
  .all {
    width: 100%;
    box-sizing: border-box;
    padding: 20px 0;
    .list {
      width: 100%;
      box-sizing: border-box;
      margin-bottom: 18px;
      padding-bottom: 20px;
      padding-top: 8px;
      box-shadow: 0 0 2px #ccc;
      .t1 {
        width: 18%;
        background-color: orangered;
        color: #fff;
        padding: 2px 15px;
        text-align: center;
        font-size: 12px;
        margin-left: 5px;
        border-top-left-radius: 20px;
        border-bottom-right-radius: 20px;
      }
      .t2,
      .t3,
      .t4,
      .t5 {
        margin-top: 25px;
        padding: 0 15px;
      }
      .t4 {
        width: 100%;
        box-sizing: border-box;
        display: flex;
        margin-bottom: 15px;
        .tu {
          width: 33.3%;
          display: flex;
          margin-top: 5px;
          .img {
            width: 60px;
            height: 60px;
            border-radius: 50%;
            margin-right: 25px;
          }
        }
      }
      .t5 {
        width: 100%;
        box-sizing: border-box;
        color: #999;
        font-size: 14px;
        .dis {
          width: 100%;
          box-sizing: border-box;
          display: flex;
          justify-content: space-between;
        }
      }
    }
  }
}
</style>
